<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;



class test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        function read_temp_api_order_info($number)
        {
            for ($i = 1; $i <= $number; $i++) {
                $temp_api_order_info = [
                    'name'           => "磊丰" . $i,
                    'email'          => 123456 + $i . '@qq.com',
                    'password'       => bcrypt("password"),
                    'remember_token' => now(),
                    'created_at'     => now(),
                    'updated_at'     => now(),
                ];
                yield $temp_api_order_info;
            }
        }


        //仓库库存扣除测试
        function cangku_stock($num = 100)
        {
            // set_time_limit(0);  //表示永久运行，这里我是测试array的时候用到的
            // $order_info = read_temp_api_order_info($num);  //这里我就测试了10条数据，效果是看不出来的

            $arr = [];
            $aa = bcrypt("password");
            for ($i = 1; $i <= $num; $i++) {
                $arr[] = [
                    'name'           => "磊丰" . $i,
                    'email'          => 123456 + $i . '@qq.com',
                    'password'       => $aa,
                    'remember_token' => now(),
                    'created_at'     => now(),
                    'updated_at'     => now(),
                ];
            }
            User::query()->insert($arr);

            // dd($arr);
        }

        $this->info(("批量更新成功" . date('Y-m-d H:i:s')));
        cangku_stock(20000);
        $this->info(("批量更新成功" . date('Y-m-d H:i:s')));
    }
}
